<?php

namespace app\index\controller\consulting;

use app\index\model\UM as UM;
use app\index\service\MessageReadService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\APP;
use think\exception\ValidateException;
use think\Request as Request;

/**
 * MessageRead 控制器
 * Class MessageRead
 * @package app\index\controller\consulting;
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 * @see \app\index\validate\consulting\MessageRead
 */
class MessageRead
{
    // 请求参数
    private Request $request;

    // service
    private MessageReadService $service;

    public function __construct(Request $request, MessageReadService $messageReadService)
    {
        $this->request = $request;
        $this->service = $messageReadService;
    }


    /**
     * 新增|修改
     * @param UM $user
     * @return ApiResponse
     * @url /consulting/message_read/save
     */
    public function save(UM $user): ApiResponse
    {
        $request = $this->request;

        if (!$request->has('id')) {
            throw new   ValidateException('请选择一个咨询');
        }

        $this->service->modify($user, $request->param('id'), $request->param());

        return ApiResponse::success(null);
    }
}
